package com.ssb.service.check;

import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.exception.BusinessException;
import com.apache.ius.plugin.CustomMethodPlugin;
import com.apache.ius.plugin.IusPluginUtil;
import com.apache.tools.DataMap;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 校验类接口
 * @Author IUS platform administrators create generation
 * @Date 2020-6-2 13:51:04
 */
@Service
public class CheckedFrontSysService {
    private Logger log = Logger.getLogger(getClass());

    /**
     * 判断前端系统是否存在且有效
     * @param frontSysCode
     * @return
     */
    public Map<String,String>  checkedSysByFrontSysCode(String frontSysCode){

        Map<String, String> result = new HashMap<String, String>();
        result.put("errorCode", "F");
        result.put("errorMsg", "系统异常!");
        //1、校验 frontSysCode 是否为空
        if (Validator.isNull(frontSysCode)){
            result.put("errorCode", "F");
            result.put("errorMsg", "前端系统代码不能为空!");
            return  result;
        }

        //根据前端系统代码 frontSysCode 判断前端请求时该系统在后台是否存在且有效
        Map selectFrontMap = new HashMap();
        selectFrontMap.put("ssFrontSystem.w_infoId",frontSysCode);
        ResultEntity obj = IusPluginUtil.getInstance().select("ssb", "obj", "s_ssFrontSystem", selectFrontMap);
        if (obj == null || obj.getEntity() == null){
            result.put("errorCode", "F");
            result.put("errorMsg", "没有该前端系统的信息，请确认后再继续操作！");
            return  result;
        }
        DataMap frontMap = (DataMap)obj.getEntity();
        String frontStatus = String.valueOf(frontMap.get("frontStatus"));
        if (frontStatus.equals("0")){
            result.put("errorCode", "F");
            result.put("errorMsg", "该前端系统无效，请确认后再继续操作！");
            return  result;
        }
        String frontApplyBrokerCode = String.valueOf(frontMap.get("frontApplyBrokerCode"));
        result.put("errorCode", "T");
        result.put("errorMsg", "识别成功！");
        result.put("frontApplyBrokerCode", frontApplyBrokerCode);
        return  result;
    }

}
